package com.gateway.plugin.api.context;

import com.gateway.common.enums.PlatformEnum;
import com.gateway.common.enums.RpcTypeEnum;
import com.google.common.collect.Maps;
import org.springframework.http.HttpMethod;
import org.springframework.http.server.PathContainer;

import java.io.Serializable;
import java.io.Serial;
import java.util.Date;
import java.util.Map;

/**
 * @program: ahcloud-gateway
 * @description: 网关上下文信息
 * @author: YuKai Fan
 * @create: 2023/1/16 08:54
 **/
public class GatewayContext implements Serializable {
    @Serial
    private static final long serialVersionUID = 9027856082823473502L;

    public static final String CACHE_GATEWAY_CONTEXT = "cacheGatewayContext";

    /**
     * ip 地址
     */
    private String ipAddress;

    /**
     * 请求源域名
     */
    private String origin;

    /**
     * 模块
     */
    private String module;

    /**
     * 请求方式
     */
    private HttpMethod method;

    /**
     * 请求路径
     */
    private String path;

    /**
     * platform
     */
    private PlatformEnum platformEnum;

    /**
     * 请求开始处理时间.
     */
    private Date startDateTime;

    /**
     * rpc类型
     */
    private RpcTypeEnum rpcType;

    /**
     * 属性
     */
    private Map<String, Object> attribute = Maps.newHashMap();

    public String getIpAddress() {
        return ipAddress;
    }

    public void setIpAddress(String ipAddress) {
        this.ipAddress = ipAddress;
    }

    public String getOrigin() {
        return origin;
    }

    public void setOrigin(String origin) {
        this.origin = origin;
    }

    public String getModule() {
        return module;
    }

    public void setModule(String module) {
        this.module = module;
    }

    public HttpMethod getMethod() {
        return method;
    }

    public void setMethod(HttpMethod method) {
        this.method = method;
    }

    public String getPath() {
        return path;
    }

    public void setPath(String path) {
        this.path = path;
    }

    public PlatformEnum getPlatformEnum() {
        return platformEnum;
    }

    public void setPlatformEnum(PlatformEnum platformEnum) {
        this.platformEnum = platformEnum;
    }

    public Date getStartDateTime() {
        return startDateTime;
    }

    public void setStartDateTime(Date startDateTime) {
        this.startDateTime = startDateTime;
    }

    public RpcTypeEnum getRpcType() {
        return rpcType;
    }

    public void setRpcType(RpcTypeEnum rpcType) {
        this.rpcType = rpcType;
    }

    public Map<String, Object> getAttribute() {
        return attribute;
    }

    public void setAttribute(Map<String, Object> attribute) {
        this.attribute = attribute;
    }


    public static final class Builder {
        private String CACHE_GATEWAY_CONTEXT;
        private String ipAddress;
        private String origin;
        private String module;
        private HttpMethod method;
        private String path;
        private PlatformEnum platformEnum;
        private Date startDateTime;
        private RpcTypeEnum rpcType;
        private Map<String, Object> attribute;

        private Builder() {
        }

        public static Builder builder() {
            return new Builder();
        }

        public Builder CACHE_GATEWAY_CONTEXT(String CACHE_GATEWAY_CONTEXT) {
            this.CACHE_GATEWAY_CONTEXT = CACHE_GATEWAY_CONTEXT;
            return this;
        }

        public Builder ipAddress(String ipAddress) {
            this.ipAddress = ipAddress;
            return this;
        }

        public Builder origin(String origin) {
            this.origin = origin;
            return this;
        }

        public Builder module(String module) {
            this.module = module;
            return this;
        }

        public Builder method(HttpMethod method) {
            this.method = method;
            return this;
        }

        public Builder path(String path) {
            this.path = path;
            return this;
        }

        public Builder platformEnum(PlatformEnum platformEnum) {
            this.platformEnum = platformEnum;
            return this;
        }

        public Builder startDateTime(Date startDateTime) {
            this.startDateTime = startDateTime;
            return this;
        }

        public Builder rpcType(RpcTypeEnum rpcType) {
            this.rpcType = rpcType;
            return this;
        }

        public Builder attribute(Map<String, Object> attribute) {
            this.attribute = attribute;
            return this;
        }

        public GatewayContext build() {
            GatewayContext gatewayContext = new GatewayContext();
            gatewayContext.setIpAddress(ipAddress);
            gatewayContext.setOrigin(origin);
            gatewayContext.setModule(module);
            gatewayContext.setMethod(method);
            gatewayContext.setPath(path);
            gatewayContext.setPlatformEnum(platformEnum);
            gatewayContext.setStartDateTime(startDateTime);
            gatewayContext.setRpcType(rpcType);
            gatewayContext.setAttribute(attribute);
            return gatewayContext;
        }
    }
}
